var gulp=require("gulp");
var rubySass=require("gulp-ruby-sass");
var uglify=require("gulp-uglify");
var webserver = require("gulp-webserver");
var livereload = require("gulp-livereload")
// var sourceMap=require("gulp-sourcemaps");
// var rename=require("gulp-rename");
// var changed=require("gulp-changed");
// var imagemin=require("gulp-imagemin");
// var pngquant=require("imagemin-pngquant");

gulp.task("shuaxin",function () {
    return gulp.src("dist")
        .pipe(webserver({
            livereload:true,
            open:true
        }))
})
//   文件搬运
gulp.task("moveHtml",function (){
    return gulp.src("src/**/*.{html,js,jpg,jpeg,gif,png,scss,css,json}")
            .pipe(gulp.dest("dist"));
});

//   编译sass
gulp.task("sass",function () {
    rubySass("src/sass/*.scss",{style:"compressed"})
        .on("error",function (err) {
            console.log(err);
        }).pipe(gulp.dest("dist/css"));
});

//   压缩脚本
// gulp.task("js",function () {
//     return gulp.src("src/js/*.js")
//         .pipe(sourceMap.init())
//         .pipe(uglify())
//         .pipe(rename({suffix:".min"}))
//         .pipe(sourceMap.write("maps"))
//         .pipe(gulp.dest("dist/js"));
// });

// //    压缩图片
// gulp.task("img",function () {
//     return gulp.src("src/image/*.{jpg,png,gif,jpeg,svg}")
//         .pipe(changed("dist/image"))
//         .pipe(imagemin({user:[pngquant]}))
//         .pipe(gulp.dest("dist/image"));
// });

//   监听
gulp.task("watch",function () {
    gulp.watch("src/**/*.{html,js,jpg,jpeg,gif,png,css,json}",["moveHtml"]);
    // gulp.watch("src/js/*.js",["js"]);
    gulp.watch("src/sass/*.scss",{style:"compressed"},["sass"]);
    // gulp.watch("src/image/*.{jpg,png,gif,jpeg,svg}",["img"]);
});
gulp.task("default",["moveHtml","sass","watch","shuaxin"]);